// pages/invoice-preview/invoice-preview.js
Page({
  data: {
    invoiceInfo: {
      invoiceNumber: '',
      invoiceCode: '',
      issueDate: '',
      patientName: '',
      idCard: '',
      department: '',
      doctor: '',
      visitDate: '',
      feeItems: [],
      totalAmount: '',
      hospitalName: '',
      taxNumber: '',
      hospitalAddress: '',
      hospitalPhone: '',
      remarks: ''
    }
  },

  onLoad: function(options) {
    // 接收发票ID参数
    const invoiceId = options.invoiceId;
    
    // 设置页面标题
    wx.setNavigationBarTitle({
      title: '发票预览'
    });

    // 获取发票信息
    this.getInvoiceInfo(invoiceId);
  },

  // 获取发票信息
  getInvoiceInfo: function(invoiceId) {
    // 模拟发票数据，实际项目中应该从API获取
    const mockInvoiceData = {
      invoiceNumber: `INV${invoiceId || '001'}${Date.now().toString().slice(-6)}`,
      invoiceCode: '123456789012345',
      issueDate: this.formatDate(new Date()),
      patientName: '张三',
      idCard: '110101199001011234',
      department: '内科',
      doctor: '李医生',
      visitDate: this.formatDate(new Date()),
      feeItems: [
        { name: '门诊挂号费', amount: '50.00' },
        { name: '诊疗费', amount: '100.00' },
        { name: '药品费', amount: '150.00' },
        { name: '检查费', amount: '200.00' }
      ],
      totalAmount: '500.00',
      hospitalName: '惠仁医院',
      taxNumber: '91110000123456789X',
      hospitalAddress: '北京市朝阳区惠仁路123号',
      hospitalPhone: '010-12345678',
      remarks: '请妥善保管发票，遗失不补'
    };

    this.setData({
      invoiceInfo: mockInvoiceData
    });
  },

  // 格式化日期
  formatDate: function(date) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    return `${year}-${month}-${day}`;
  },





  // 返回上一页
  goBack: function() {
    wx.navigateBack({
      delta: 1
    });
  },


});
